<%@ page pageEncoding="UTF-8"%>
<%@ include file="../common/global.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="../common/meta.jsp"%>
<title><f:message key="common.title" /> - <f:message key="user" /></title>
<%@ include file="../common/css.jsp"%>
</head>
<body>
<c:set var="user" value="${userBean.user}"/>
<c:set var="userRoleList" value="${userBean.roleList}"/>
<div id="wrapper">
    <%@ include file="../common/topbar.jsp" %>
    <%@ include file="../common/header.jsp" %>
    <div id="masthead">
        <div class="container">

            <div class="masthead-pad">

                <div class="masthead-text">
                    <h5> <f:message key="user.edit_user" /></h5>
                </div> <!-- /.masthead-text -->

            </div>

        </div> <!-- /.container -->

    </div> <!-- /#masthead -->

    <div id="content">
        <div class="container">
            <div class="row">
                <div class="span12">

                    <form class="form-horizontal" id="user_edit_form">
                    <fieldset>

                        <div class="control-group">
                            <div class="controls">
                            <input type="hidden" id="id" value="${user.id}">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="username"><f:message key="user.username"/>:</label>
                            <div class="controls">
                            <input type="text" id="username" value="${user.username}" class="input-large css-readonly" readonly>
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="password"><f:message key="user.password"/>:</label>
                            <div class="controls">
                                <input type="text" id="password" name="password" class="input-large">
                                <span class="badge badge-primary"><f:message key="user.password.tip"/></span>
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label"><f:message key="user.role"/> </label>
                            <div class="controls">
                            <tag:role roleList="${roleList}" userRoleList="${userRoleList}"/>
                            </div>
                        </div>

                        <div class="form-actions">
                            <button type="submit" class="btn btn-default">
                                <f:message key="common.save" />
                            </button>
                            <button type="button" id="back" class="btn btn-default">
                                <f:message key="common.back" />
                            </button>
                        </div>

                    </fieldset>
                    </form>

                </div> <!-- /.span12 -->
            </div> <!-- /.row -->
        </div> <!-- /.container -->
    </div> <!-- /#content -->
</div> <!-- /#wrapper -->

	<%@ include file="../common/footer.jsp"%>
	<%@ include file="../common/js.jsp"%>

	<script type="text/javascript">
        $(function() {
            $('#user_edit_form').ajaxForm({
                type: 'put',
                url: BASE + '/user/' + $('#id').val(),
                dataType: 'json',
                beforeSubmit: function() {
                    return Smart.Validator.checkRequired('user_edit_form');
                },
                success: function(result) {
                    if (result.success) {
                        location.href = BASE + '/users';
                    }
                }
            });

            $('#save').click(function() {
                $('#user_edit_form').submit();
            });

            $('#back').click(function() {
                location.href = BASE + '/users';
            });
        });
	</script>


</body>
</html>